
#include "TagDialog.h"
#include <QtGui/QApplication>
#include <QDialogButtonBox>
#include <QGroupBox>
#include <QCheckBox>
//#include <QComboBox>
#include <QPushButton>
#include "Tag.h"
#include <QFontDialog>


//-------------------------------------

TagDialog::TagDialog( Tag * t, QWidget *parent ) :
    QDialog( parent )
{
    tag = t;
    resize( 900, 250 );
    buttonBox = new QDialogButtonBox( this );
    buttonBox->setGeometry( QRect(400, 150, 160, 25 ) );
    buttonBox->setOrientation( Qt::Horizontal );
    buttonBox->setStandardButtons( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );
    groupBox = new QGroupBox( this );
    //groupBox->setGeometry( QRect( 10, 0, 280, 140) );
    btnFont = new QPushButton( groupBox );
    //btnFont->setGeometry( QRect( 100, 110, 75, 25 ) );
    teTagText = new QTextEdit( groupBox );
    //teTagText->setGeometry( QRect( 10, 20, 260, 80 ) );
    grbshowParamList = new QGroupBox( this );
    //grbshowParamList->setGeometry( QRect( 300, 0, 270, 140 ) );
    teParamToShow = new QTextEdit( grbshowParamList );
    //teParamToShow->setGeometry( QRect( 10, 20, 255, 80 ) );

    chbShowParams = new QCheckBox( this );
    //chbShowParams->setGeometry( QRect( 15, 150, 110, 20 ) );
    chbShowParams->setChecked( tag->ShowParamStr() );

    buttonBox->setGeometry(QRect(410, 190, 161, 25));
    groupBox->setGeometry(QRect(6, 0, 730, 141));
    btnFont->setGeometry(QRect(330, 110, 77, 25));
    teTagText->setGeometry(QRect(10, 20, 710, 80));
    grbshowParamList->setGeometry(QRect(744, 0, 150, 141));
    teParamToShow->setGeometry(QRect(10, 20, 130, 80));
    chbShowParams->setGeometry(QRect(240, 150, 110, 20));

    setWindowTitle( QApplication::translate( "TagDialog", "Tag Dialog", 0, QApplication::UnicodeUTF8 ) );
    groupBox->setTitle( QApplication::translate( "TagDialog", "Text", 0, QApplication::UnicodeUTF8 ) );
    btnFont->setText( QApplication::translate( "TagDialog", "Font", 0, QApplication::UnicodeUTF8 ) );
    grbshowParamList->setTitle( QApplication::translate( "TagDialog", "Show Following Parameters", 0, QApplication::UnicodeUTF8 ) );
    chbShowParams->setText( QApplication::translate( "TagDialog", "Show Parameters", 0, QApplication::UnicodeUTF8 ) );

    connect( buttonBox, SIGNAL( accepted() ),  this , SLOT( accept() ) );
    connect( buttonBox, SIGNAL( rejected() ),  this , SLOT( reject() ) );
    connect( btnFont, SIGNAL( clicked() ), this, SLOT( sltFont() ) );

    fmt.setFontFamily( TAG_DEFAULT_FONT_FAMILY );
    fmt.setFontPointSize( TAG_DEFAULT_FONT_SIZE );
    fmt.setFontWeight( QFont::Bold );

    if( tag )
    {
        teTagText->setPlainText( tag->GetText() );
        QStringList * l = tag->GetShownParamList();
        for( int i=0; i < l->count(); i++ )
            teParamToShow->append( l->at( i ) );
    }
}

//-------------------------------------

void TagDialog::sltFont()
{
    bool ok;
    QFont f;
    f.setFamily( fmt.font().family() );
    f.setPointSize( fmt.font().pointSize() );
    f = QFontDialog::getFont( &ok, f );
    if( ok )
    {
        fmt.setFont( f );
        teTagText->setCurrentCharFormat( fmt );
    }
}

//-------------------------------------

int TagDialog::Exec()
{
    int res = exec();
    if( res == QDialog::Accepted )
    {
        tag->SetText( teTagText->document()->toPlainText() );
        tag->SetFont( fmt.font() );
        tag->ShowParamStr( chbShowParams->isChecked() );
        QStringList l = teParamToShow->toPlainText().split( "\n" );
        tag->SetShownParamList( l );
    }
    return res;
}

//-------------------------------------










